package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.EstateAdviserService;
import com.yixun.qfbao.api.service.PremisesRecommenderService;
import com.yixun.qfbao.apidto.*;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetPremisesDetailReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service("estateAdviserListHander")
public class EstateAdviserListHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(EstateAdviserListHander.class);

    @Autowired
    EstateAdviserService estateAdviserService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GetPremisesDetailReqVo req = (GetPremisesDetailReqVo)reqDto;
        GetPremisesDetailReqDto reqDto1 = req.getParams();
        BaseResponseDTO<EstateAdviserListResDto> res = new BaseResponseDTO<>();
        EstateAdviserListResDto resDto = new EstateAdviserListResDto();
        try {
            if(Objects.isNull(reqDto1.getId())){
                res.setResult(ResultEnum.FAIL.getNo());
                res.setErrorMsg("楼盘不能为空!");
                return res;
            }
            ListEstateAdviserByPremisesIdReqDto listReqDto = new ListEstateAdviserByPremisesIdReqDto();
            listReqDto.setPremisesId(reqDto1.getId());
            ListEstateAdviserByPremisesIdResDto listResDto = estateAdviserService.listEstateAdviserByPremisesId(listReqDto);
            resDto.setList(listResDto.getList());
            resDto.setResult(ResultEnum.SUCCESS.getNo());
            res.setResData(resDto);
            res.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            logger.error("premisesId: {}, estateAdviserListHander error: {}", reqDto1.getId(), e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("推荐人查询失败!");
        }
        return res;
    }
}
